package com.qj.yantaishan.controller;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qj.yantaishan.common.annotation.Log;
import com.qj.yantaishan.common.enums.BusinessType;
import com.qj.yantaishan.domain.StoreMessage;
import com.qj.yantaishan.service.IStoreMessageService;
import com.qj.yantaishan.common.core.controller.BaseController;
import com.qj.yantaishan.common.core.domain.AjaxResult;
import com.qj.yantaishan.common.utils.poi.ExcelUtil;
import com.qj.yantaishan.common.core.page.TableDataInfo;

/**
 * 店铺信息Controller
 * 
 * @author qihe
 * @date 2022-07-22
 */
@RestController
@RequestMapping("/yantaishan/StoreMessage")
public class StoreMessageController extends BaseController
{
    private String prefix = "yantaishan/StoreMessage";

    @Autowired
    private IStoreMessageService storeMessageService;

    @RequiresPermissions("yantaishan:message:view")
    @GetMapping()
    public String message()
    {
        return prefix + "/message";
    }

    /**
     * 查询店铺信息列表
     */
    @RequiresPermissions("yantaishan:message:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StoreMessage storeMessage)
    {
        startPage();
        List<StoreMessage> list = storeMessageService.selectStoreMessageList(storeMessage);
        return getDataTable(list);
    }

    /**
     * 导出店铺信息列表
     */
    @RequiresPermissions("yantaishan:message:export")
    @Log(title = "店铺信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StoreMessage storeMessage)
    {
        List<StoreMessage> list = storeMessageService.selectStoreMessageList(storeMessage);
        ExcelUtil<StoreMessage> util = new ExcelUtil<StoreMessage>(StoreMessage.class);
        return util.exportExcel(list, "店铺信息数据");
    }

    /**
     * 新增店铺信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存店铺信息
     */
    @RequiresPermissions("yantaishan:message:add")
    @Log(title = "店铺信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StoreMessage storeMessage)
    {
        return toAjax(storeMessageService.insertStoreMessage(storeMessage));
    }

    /**
     * 修改店铺信息
     */
    @RequiresPermissions("yantaishan:message:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        StoreMessage storeMessage = storeMessageService.selectStoreMessageById(id);
        mmap.put("storeMessage", storeMessage);
        return prefix + "/edit";
    }

    /**
     * 修改保存店铺信息
     */
    @RequiresPermissions("yantaishan:message:edit")
    @Log(title = "店铺信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StoreMessage storeMessage)
    {
        return toAjax(storeMessageService.updateStoreMessage(storeMessage));
    }

    /**
     * 删除店铺信息
     */
    @RequiresPermissions("yantaishan:message:remove")
    @Log(title = "店铺信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(storeMessageService.deleteStoreMessageByIds(ids));
    }
}
